package com.baizhi.controller;

import com.baizhi.entity.Department;
import com.baizhi.service.DepartmentService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("department")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    @RequestMapping("show")
    @ResponseBody
    public Map showDepartment(Integer page,Integer limit,String name){
        Map map = new HashMap();
        PageInfo<Department> pageInfo = departmentService.selectByPage(page, limit, name);
        map.put("code",0);
        map.put("msg","");
        map.put("count",pageInfo.getTotal());
        map.put("data",pageInfo.getList());
        return map;
    }
    @RequestMapping("remove")
    @ResponseBody
    public Map removeDepartment(Integer did){
        Map map = new HashMap();
        int i = departmentService.delete(did);
        if(i==0){
            map.put("flag",false);
        }else{
            map.put("flag",true);
        }
        return map;
    }
    @RequestMapping("add")
    @ResponseBody
    public Map addDepartment(Department department){
        Map map = new HashMap();
        int i = departmentService.insert(department);
        if(i==0){
            map.put("flag",false);
        }else{
            map.put("flag",true);
        }
        return map;
    }
    @RequestMapping("removeAny")
    @ResponseBody
    public Map removeAnyDepartment(int[] dids){
        Map map = new HashMap();
        int i = departmentService.deleteAny(dids);
        if(i==0){
            map.put("flag",false);
        }else{
            map.put("flag",true);
        }
        return map;
    }
    @RequestMapping("update")
    @ResponseBody
    public Map updateDepartment(Department department){
        System.out.println("更新收参="+department);
        Map map = new HashMap();
        int i = departmentService.update(department);
        if(i==0){
            map.put("flag",false);
        }else{
            map.put("flag",true);
        }
        return map;
    }
    @RequestMapping("getOne")
    @ResponseBody
    public Department getOneDepartment(Integer did){
        Department department = departmentService.selectById(did);
        return department;
    }
    @RequestMapping("selectAll")
    @ResponseBody
    public List<Department> selectAll(){//查询所有科室  挂号时显示下拉框
        List<Department> departments = departmentService.selectDepartments();
        return departments;
    }
    @RequestMapping("selectByTriageStatus")
    @ResponseBody
    public Map selectByTriageStatus(){//查询每个科室下正在等待的患者数量
        Map map = new HashMap();
        List<Department> departments = departmentService.selectTriageStatus();
        map.put("code",0);
        map.put("msg","");
        map.put("count",departments.size());
        map.put("data",departments);
        return map;
    }
    @RequestMapping("selectByTriageStatus2")
    @ResponseBody
    public Map selectByTriageStatus2(){//查询每个科室下正在等待的患者数量
        Map map = new HashMap();
        List<Department> departments = departmentService.selectTriageStatus();
        map.put("pages",1);
        map.put("departments",departments);
        return map;
    }
}
